<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>注册</button>
    <div id="btn">我是商品数据导入</div>
    <input type="text" id="space_text">
    <script>
        // let c = 1
        // function a(){
        //     b()
        // }
        // function b(){
        //     console.log(c)
        // }
        // a()
        // console.log(Boolean([]))
        const button = document.querySelector('button')
        button.onclick = function (){
            const ajax = new XMLHttpRequest
            ajax.open('post','http://localhost:65535/register',true)
            ajax.onreadystatechange = function(){
                if(ajax.readyState == 4){
                    if(ajax.status >= 200 && ajax.status < 300){
                        console.log(JSON.parse(ajax.response))
                    }
                }
            }
            ajax.setRequestHeader('Content-type','application/x-www-form-urlencoded')
            ajax.send('username=admin&password=123')
        }
        btn.onclick = function(){
            const xhr = new XMLHttpRequest
            xhr.open('get','http://localhost:65535/goodsup',true)
            xhr.onreadystatechange = function(){
                if(xhr.readyState == 4){
                    if(xhr.status >= 200 && xhr.status < 300){
                        console.log(xhr.response)
                    }
                }
            }
            xhr.send()
        }

        // 测试cookie
        // let d = new Date
        // document.cookie = `user=wwww`

        // 替换空格为空字符
        const space_text = document.getElementById('space_text')
        let time_out
        space_text.oninput = function(){
            // replaceAll("\\u00A0+", "") js没有replaceAll方法
            clearTimeout(time_out)
            time_out = setTimeout(() => {
                this.value = this.value.replace(new RegExp(' ','g'),'')
                console.log(this.value.replace(new RegExp(' ','g'),''))
            }, 2000);
        }

        // 这样写，a=6，赋最后一个值
        // let a = (1,2,3,4,5,6)
        // console.log(a)

        /* console.log(1)
        onclick = function(){
            console.log(1)
        }
            
        for(let i=0;i<1000;i++){
            console.log('for')
        } */ // 测试同步异步
    </script>
    
    <!-- <script>
        setTimeout(() => {
            console.log('timeout')
        }, 2000);
    </script>
    <script>
        // console.log(1)
        setTimeout(() => {
            console.log(2000)
        }, 2000);
    </script> -->
</body>
</html>